package fsoft.com.vn.directory.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import fsoft.com.vn.directory.form.Login;
import fsoft.com.vn.directory.service.LoginService;

@Controller
public class  LoginController{

	@Autowired
	private LoginService loginService;

	@RequestMapping("/loginform")
	public String showform() {
	return "loginform";
	}
	
	@RequestMapping("/menu")
	public String showmenu() {
	return "menu";
	}
	
	@RequestMapping("/")
	public String indexpage(){
		return "redirect:loginform";
   }
	
	@RequestMapping("/login")
	public String LoginAuthentication(HttpServletRequest req){
        String username=req.getParameter("name");
        String password=req.getParameter("pass");
		Login login = loginService.checklogin(username,password);
		if(login != null)
			return "redirect:Govs";
		else return "redirect:loginform";
   }
}
